<?php

use Illuminate\Database\Seeder;

class PostTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $users = \App\User::all();
        $tags = \App\Tag::all();
        foreach ($users as $user) {
            for ($i = 0; $i < count($tags); $i++) {
                $post = factory(\App\Post::class)->create([
                    'user_id' => $user->id,
                ]);
                \App\PostTag::query()->create([
                    'post_id' => $post->id,
                    'tag_id' => $tags[$i]->id,
                ]);
            }
        }
    }
}
